<?php
//由ThinkphpHelper自动生成,请根据需要修改
namespace TPH\Model;
use Think\Model;

class TopicModel extends Model {
	protected $connection = 'DB_MG_CHANPIN';
	protected $tableName = '';
	protected $tablePrefix = 'cms01_';
    /*
     * 自动验证规则设置
     * 示例:     
     * protected $_validate = array(
     *      array('username','require','用户名必须填写'),
     *      array('password','require','密码必须填写'),
     *      array('password2','require','确认密码必须填写'),
     *      array('password2','password','与密码的信息必须一致',0,'confirm'),
     *      array('user_email','email','邮箱格式不正确',2),
     *      array('user_qq','/^[1-9]\d{4,9}$/','qq格式不正确'),
     *      array('user_xueli','2,3,4,5','必须选择一个学历',0,'in'),
     *      array('user_hobby','check_hobby','爱好必须两项以上',1,'callback'),
     * );    
     */
    protected $_validate = array(
         array('title','require','专题名称必须填写'),
    );

    /*
     * 自动完成规则设置
     * 示例:     
     * protected $_auto=array(    
     *      array('addtime','time',1,'function'),
     *      array('update_time','time',3,'function'), 
     *      array('add_admin_id','curLoginAdminId',1,'callback'), 
     *      array('update_admin_id','curLoginAdminId',3,'callback'),                     
     *   );      
     */
    protected $_auto=array(     
           array('add_time','returnCurDatetime',1,'callback'),
           array('update_time','returnCurDatetime',3,'callback'),                       
    );

	//自定义回调返回时间基本函数
    function returnCurDatetime(){
        $datetime=date('Y-m-d H:i:s',time());    
        return $datetime;        
    }

	/*
	 * 字段别名定义：
	 * $return_field_alias_dict=array('字段名1'=>'中文名1','字段名2'=>'中文名2','字段名3'=>'中文名3',...'字段名n'=>'中文名n')
	 */
	public function fieldAliasDict() {
	    $return_field_alias_dict	=	array(
		    'id'=>'自增ID', 
		    	
			'title'=>'专题名称', 
		    	
			'add_time'=>'添加时间', 
		    
			'update_time'=>'修改时间', 

			'img'=>'专题图片', 
		    	
			'game'=>'专题游戏', 
		    	
			'sort'=>'排序', 

			'note'=>'简介'
		    	                    
	    );
		return $return_field_alias_dict;
	}

	/*
	 * 列表数据字段显示定义：
	 * $return_list_field_dict=array('字段名1','字段名2','字段名3',......'字段名n')
	 */
    public function listFieldDict() {
        $return_list_field_dict	=	array(
		    'id','title','img','game','sort','update_time','add_time'    
        );
		return $return_list_field_dict;
    }

	/*
	 * 输入表单数据字段类型定义与显示
	 * 示例: 
	 * $return_form_field_dict	=	array(
	 *			'name'	=>	array('inType' => 'text','required'=>1),
	 *			'desc'	=>	array('inType' => 'textarea'),
	 *            'status'  =>  array('inType' => 'radio','options'=>array('0'=>'关闭','1'=>'开启')),
	 *            'test_online_time'  =>  array('inType' => 'datetime'),      
	 *            'test_chk'  =>  array('inType' => 'checkbox','options'=>array('1'=>'胖','2'=>'壮','3'=>'美')),   
	 *            'test_select'  =>  array('inType' => 'select','options'=>array('0'=>'请选择','5'=>'勤奋','6'=>'好学')), 
	 *            'test_select2'  =>  array('inType' => 'select','multiple'=>1,'field_comma_split'=>1,'options'=>D('ChanPinGame')->getField('game_id, game_cname')),  	  
	 *            'text_img'=>    array('inType' => 'file','index'=>2),    
	 *            'text_conent'=>    array('inType' => 'editor'),                                              
	 * );	 	  
	 */
    public function formFieldDict() {
     	$game_list_temp_arr=D('ChanPinGame')->order('game_id desc')->getField('game_id, game_cname');
        $game_list_arr=count($game_list_temp_arr) && is_array($game_list_temp_arr)?$game_list_temp_arr:array();        
        $games = [0=>'请选择'] + $game_list_arr;   	
        $return_form_field_dict	=	array(
			'title'=>array('inType' => 'text','required'=>0),  
		    	
			'img'=>array('inType' => 'file','index'=>1,'required'=>1),  
		    	
			'note'=>array('inType' => 'textarea','required'=>1),  

			'game'=>array('inType' => 'select','multiple'=>1,'required'=>1,'field_comma_split'=>1,'options'=>$games,'required'=>1),  
		    	
			'sort'=>array('inType' => 'text','required'=>1),  	

		);

		return $return_form_field_dict;
    }

    /*
     * 搜索字段类型定义与显示
     * 示例:     
     *  $return_search_field_dict =   array(
     *             'name'  =>  array('inType' => 'text','dataType'=>'varchar'),
     *             'test_online_time'  =>  array('inType' => 'datetime','dataType'=>'varchar'),
     *             'test_select'  =>  array('inType' => 'select','dataType'=>'int','options'=>array('0'=>'请选择','5'=>'勤奋','6'=>'好学')),                                                       
     *  );     
     */
    public function searchFieldDict() {    	
        $return_search_field_dict =   array(
		    	
			'title'=>array('inType' => 'text','dataType'=>'varchar'), 
		    	
			'add_time'=>array('inType' => 'datetime','dataType'=>'varchar'),                                                            
        );

        return $return_search_field_dict;
    }



}